package com.wpp.algorithm.lagou.part1.lesson2;

/**
 * @author wpp25
 * @date 2021/5/12 22:08
 * @description：
 */
public class Part2_2 {

    public static void main(String[] args) {
        System.out.println(getSum(-2,1));
    }

    //无进位加法使用异或运算计算得出,进位结果使用与运算和移位运算计算得出;
    public static int getSum(int a, int b) {
        if (b!=0){
            int xor=a^b;
            int and = (a&b)<<1;
            return getSum(xor,and);
        }else{
            return a;
        }
    }
}
